//
//  XS_Float.swift
//  XS_GameTemplate
//
//  Created by 韩云智 on 2020/6/29.
//  Copyright © 2020 韩云智. All rights reserved.
//

import UIKit

public extension CGFloat {
    static let safeSpace: CGFloat = Swift.max(0, .bottomHeight-20)
    static let radian = CGFloat.pi / 180
    static let screenSize = UIScreen.main.bounds.size
    static let screenWidth = Swift.min(screenSize.width, screenSize.height)
    static let screenHeight = Swift.max(screenSize.width, screenSize.height)
    /// 以屏幕宽度为基准的缩放系数
    static let scale = screenWidth / 375.0
    ///  刘海屏底部高度 区分刘海屏
    static let bottomHeight = xsSafeBottom()
    static func xsSafeBottom() -> CGFloat {
        if #available(iOS 11.0, *) {
            return xsWindow()?.safeAreaInsets.bottom ?? 0
        } else {
            return 0
        }
    }
    /// 状态栏高度 区分刘海屏
    static let barHeight = xsStatusBarFrame().size.height
    static func xsStatusBarFrame() -> CGRect {
        if #available(iOS 13.0, *) {
            return UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero
        } else {
            return UIApplication.shared.statusBarFrame
        }
    }
}
